#!/usr/bin/env node

const http = require('http'),
      url = require('url'),
      qs = require('querystring');
//url:http://localhost:8080/add?x=2&y=3
http.createServer((req,res)=>{
  const addr = url.parse(req.url);
  if(addr.pathname === '/add'){
    const arg = qs.parse(addr.query);
    const r = {};
    r.add = Number(arg.x) + Number(arg.y);
    res.end(JSON.stringify(r));
  }
  res.end('ok');
}).listen(8080)
